<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <script src="/static/layui/layui.js" charset="utf-8"></script>
    <script src="/static/layui/ycTools.js" charset="utf-8"></script>
    <script src="/static/layui/ycNoImportents.js" charset="utf-8"></script>
    <link rel="stylesheet" href="/static/layui/css/layui.css" media="all">
    <!--依据各级供电单位的不同类别、型号、批次的计量设备，分析展示计量设备在不同状态时的平均停留时间及单个设备停留时间-->
<body>
<br>
<form class="layui-form" action="" id="searchForm">
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">供电单位</label>
            <div class="layui-input-inline">
                <input type="text" name="depart_id"  id="depart_id" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">型号</label>
            <div class="layui-input-inline">
                <input type="text" name="Devmodel" id="Devmodel" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <button type="button" onclick="doSearch();" class="layui-btn layui-btn-sm">搜索</button>
            <button type="reset" class="layui-btn layui-btn-sm">重置</button>
        </div>
    </div>
</form>
<table class="layui-hide" id="test" lay-filter="test"></table>

<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <!--<button class="layui-btn layui-btn-sm" lay-event="getCheckData">获取选中行数据</button>-->
        <!--<button class="layui-btn layui-btn-sm" lay-event="getCheckLength">获取选中数目</button>-->
        <button class="layui-btn layui-btn-sm" lay-event="isAll">验证是否全选</button>
        <!--<button class="layui-btn layui-btn-sm" lay-event="add">添加</button>-->
    </div>
</script>
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="singleDevDetail">详细</a>
    <!--<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>-->
</script>

<script>
    var $,table;
    layui.use('table', function(){
        table = layui.table;
        $ = layui.jquery;
        table.render({
            elem: '#test'
            ,url:"/devices/devicesStateDepTab"
            ,toolbar: '#toolbarDemo'
            ,title: '设备数据表'
            ,height: 'full-80' //高度最大化减去差值
            ,totalRow: true
            ,parseData: function(res){ //res 即为原始返回的数据
                var dataHandleOne=[];

                dataHandleOne= devicesStateDep_rowsHandle_ycNI(res.rows);
                return { //参考response的定义
                    "code": res.currentPage, //解析接口状态
                    "msg":  res.pageSize, //解析提示文本
                    "total": dataHandleOne.length, //解析数据长度
                    "rows": dataHandleOne //解析数据列表
                };
            }
            ,cols: [[
                {type: 'numbers', fixed: 'left', rowspan: 2}
                ,{field:'id', title: 'ID', width:80,hide:true, rowspan: 2}
                //,{field:'id', title:'ID', width:80, fixed: 'left', unresize: true, sort: true, totalRowText: '合计'}
                ,{field:'depart_id', title:'供电单位',width:180, rowspan: 2}
                ,{field:'devices_totals', title:'总设备数',width:110, rowspan: 2,sort: true}
                ,{field:'devices_states', title:'总状态数',width:110, rowspan: 2,sort: true}
                ,{field:'devices_state_totals', title:'设备不同状态数',width:130, rowspan: 2}
                ,{field:'diff_model', title:'不同型号数',width:110, rowspan: 2}
                ,{align: 'center', title: '设备与状态明细', colspan: 2} //colspan即横跨的单元格数，这种情况下不用设置field和width

                ,{fixed: 'right', title:'单个设备分析', width:120,toolbar: '#barDemo', rowspan: 2}
            ], [
                {field:'modelState_totals', title:'型号总状态数', rowspan: 2}//PACS-5612F006:6台;状态数:5种
                ,{field:'stateOutTime_detail', title:'设备状态的平均停留时间', rowspan: 2,templet: function(d){
                    return (d.stateOutTime_detail).replaceAll_yc("-!-","  ");
                }}
            ]]
            ,response: {
                statusName: 'code' //规定数据状态的字段名称，默认：code
                ,statusCode: 0 //规定成功的状态码，默认：0
                ,msgName: 'msg' //规定状态信息的字段名称，默认：msg
                ,countName: 'total' //规定数据总数的字段名称，默认：count
                ,dataName: 'rows' //规定数据列表的字段名称，默认：data
            }
            ,page: true
            ,limit:8
            ,limits:[8,10,20,30]
            ,id:'devicesTable'
        });

        //工具栏事件
        table.on('toolbar(test)', function(obj){
            var checkStatus = table.checkStatus(obj.config.id);
            switch(obj.event){
                case 'getCheckData':
                    var data = checkStatus.data;
                    layer.alert(JSON.stringify(data));
                    break;
                case 'getCheckLength':
                    var data = checkStatus.data;
                    layer.msg('选中了：'+ data.length + ' 个');
                    break;
                case 'isAll':
                    layer.msg(checkStatus.isAll ? '全选': '未全选')
                    break;
                case 'add':
                    //layer.msg('弹出添加页面');
                    parent.layer.open({
                        type:2,//2跳转到页面
                        offset: 'auto',
                        title:'添加课程订单',
                        content:'/courseorder/add',
                        area: ['1000px', '600px'],
                        btn:'关闭全部',
                        btnAlign:'c',
                        yes:function () {
                            parent.layer.closeAll();
                        }
                    });
                    break;
            };
        });


        //监听行双击事件
        table.on('rowDouble(test)', function(obj) {
            console.log(obj.data) //得到当前行数据
            /* var orderId = obj.data.order_id;
            parent.layer.open({
                type:2,//2跳转到页面
                offset: 'auto',
                title:'双击事件详情',
                content:'/courseorder/detail?order_id='+ orderId,
                area: ['100px', '100px'],
                btn:'关闭全部',
                btnAlign:'c',
                yes:function () {
                    parent.layer.closeAll();
                }
            });*/
        });

        //监听工具条
        table.on('tool(test)', function(obj){ //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
            console.log();
            var depart_id = obj.data.depart_id; //供电单位
            var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
            if(layEvent === 'del'){ //删除
                layer.confirm('真的删除行么', function(index){
                    obj.del(); //删除对应行（tr）的DOM结构，并更新缓存
                    layer.close(index);

                    //向服务端发送删除指令,jqery.get
                    $.get("/courseorder/delete",{order_id:orderId},function (respData) {
                        console.log(respData);
                        if(respData.success == 1){
                            layer.msg("删除成功");
                        }else{
                            layer.msg("删除失败" + resp.message);
                        }
                    })
                });
            } else if(layEvent === 'singleDevDetail'){ //编辑
                //弹出编辑页面
                layer.open({
                    type:2,//2跳转到页面
                    offset: 'auto',
                    title:'设备停留时间分析',
                    content:'/devices?singleDevDetailTab&depart_id='+depart_id,
                    area: ['900px', '460px'],
                    btn:'关闭全部',
                    btnAlign:'c',
                    yes:function () {
//                        parent.layer.closeAll();
                        layer.closeAll();
                    }
                });
            }
        });
    });

    function doSearch(){  //搜索
        //通过jquery获取参数
        var Devmodel = $("#Devmodel").val();
        var depart_id = $("#depart_id").val();
console.log(Devmodel);
        //table.reaload方法,附加上搜索条件
        table.reload('devicesTable', {
            where: {//附加额外的参数
                Devmodel:Devmodel,
                depart_id:depart_id
            },page: {
                curr: 1 //重新从第 1 页开始
            }
        });
    }
</script>

</body>
</html>